'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('inventory_adjustments', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      organization_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        comment: '组织ID'
      },
      product_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        comment: '产品ID'
      },
      sku: {
        type: Sequelize.STRING(100),
        allowNull: false,
        comment: '产品SKU'
      },
      product_name: {
        type: Sequelize.STRING(200),
        allowNull: false,
        comment: '产品名称'
      },
      before_stock: {
        type: Sequelize.INTEGER,
        allowNull: false,
        comment: '调整前库存'
      },
      after_stock: {
        type: Sequelize.INTEGER,
        allowNull: false,
        comment: '调整后库存'
      },
      adjust_quantity: {
        type: Sequelize.INTEGER,
        allowNull: false,
        comment: '调整数量'
      },
      adjust_type: {
        type: Sequelize.ENUM('increase', 'decrease', 'set'),
        allowNull: false,
        comment: '调整类型: increase-增加, decrease-减少, set-设置为'
      },
      reason: {
        type: Sequelize.STRING(100),
        allowNull: true,
        comment: '调整原因'
      },
      remark: {
        type: Sequelize.TEXT,
        comment: '备注'
      },
      operator_id: {
        type: Sequelize.INTEGER,
        allowNull: true,
        comment: '操作人ID'
      },
      operator_name: {
        type: Sequelize.STRING(100),
        allowNull: true,
        comment: '操作人姓名'
      },
      created_at: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updated_at: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });
  },
  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable('inventory_adjustments');
  }
};